package com.xframe.event.bus.core.model;

import lombok.Data;

import java.util.Date;

/**
 * 数据变更消息
 */
@Data
public class DataMessage {

    public static final String CREATE = "CREATE";
    public static final String UPDATE = "UPDATE";
    public static final String DELETE = "DELETE";
    public static final String LOGICAL_DELETE = "LOGICAL_DELETE";
    public static final String LOGICAL_DELETE_IDS = "LOGICAL_DELETE_IDS";
    public static final String ENABLE_MODEL = "ENABLE_MODEL";
    public static final String ENABLE_MODEL_IDS = "ENABLE_MODEL_IDS";
    public static final String DELETE_IDS = "DELETE_IDS";
    public static final String LOGIN = "LOGIN";
    public static final String LOGOFF = "LOGOF";
    public static final String IMPORT = "IMPORT";

    /**
     * 数据类型
     */
    private String dataType;
    /**
     * 动作  CREATE UPDATE DELETE LOGIN LOGOF等
     */
    private String action;
    /**
     * 单条数据的主键
     */
    private String dataKeyID;
    /**
     * 附加参数
     */
    private String args;
    /**
     * 附加数据
     */
    private Object data;
    /**
     * 时间戳
     */
    private Long when;
    /**
     * 消息发送系统
     */
    private String sysName;

    /**
     * 消息发送系统
     */
    private String opUser;


    public static DataMessage valueOf(String dataType,String action,String dataKeyID,String args,
                                      Object data,String sysName,String opUser){
        DataMessage dataMessage = new DataMessage();
        dataMessage.data = data;
        dataMessage.dataKeyID = dataKeyID;
        dataMessage.dataType = dataType;
        dataMessage.action = action;
        dataMessage.args = args;
        dataMessage.sysName = sysName;
        dataMessage.when = new Date().getTime();
        dataMessage.opUser = opUser;
        return dataMessage;
    }

    public static DataMessage valueOf(String dataType,String action,String dataKeyID,String args,String sysName,String opUser){
        return valueOf(dataType,action,dataKeyID,args,null,sysName,opUser);
    }

    public static DataMessage valueOf(String dataType,String action,String dataKeyID,String sysName,String opUser){
        return valueOf(dataType,action,dataKeyID,"",null,sysName,opUser);
    }

}
